package org.hgvc.webapp.ets.jsf.beans.admin;

import java.util.List;

import javax.faces.component.UIParameter;
import javax.faces.event.ActionEvent;

import org.hgvc.webapp.ets.bo.ReInstateFreeTrx;
import org.hgvc.webapp.ets.spring.service.MembershipService;
import org.jocsb.base.AbstractBean;
import org.jocsb.base.exception.BaseException;


public class AdminReinstateFreeTrxBean extends AbstractBean {

	public static final String BEAN_NAME="adminReinstateFreeTrxBean";
	public static final String NAV_LIST="adminReinstateList";
	public static final String NAV_CREATE="adminReinstateCreate";
	public static final String NAV_EDIT="adminReinstateEdit";
	
	private MembershipService service;
	private ReInstateFreeTrx reinstate;
	private List<ReInstateFreeTrx> resList;
	public ReInstateFreeTrx getReinstate() {
		return reinstate;
	}
	public void setReinstate(ReInstateFreeTrx reinstate) {
		this.reinstate = reinstate;
	}
	public void setService(MembershipService service) {
		this.service = service;
	}
	/*------------------------------------------------------------*/
	public String navListAction(){
		return NAV_LIST;
	}
	
	public List<ReInstateFreeTrx> getResList() {
		try{
			resList = service.getReInstateFreeTrxList();
		}catch(BaseException be){
			initErrorBean(be);
			be.printStackTrace();
		}
		return resList;
	}
	
	public String navCreateAction(){
		reinstate = new ReInstateFreeTrx();
		return NAV_CREATE;
	}
	
	public String createAction(){
		try{
			service.createReInstateFreeTrx(this.reinstate, getThisUser());
			return NAV_LIST;
		}catch(BaseException be){
			initErrorBean(be);
			be.printStackTrace();
		}
		return NAV_CREATE;
	}
	
	public void editActionListener(ActionEvent ae){
		UIParameter param = (UIParameter)ae.getComponent().findComponent("resId");
		String id = (String)param.getValue();
		for(ReInstateFreeTrx t:resList){
			if(t.getReInstateFreeTrxId().equalsIgnoreCase(id)){
				reinstate = t;
				break;
			}
		}
	}
	
	public String navEditAction(){
		return NAV_EDIT;
	}
	
	public String editAction(){
		try{
			service.editReInstateFreeTrx(reinstate, getThisUser());
			return NAV_LIST;
		}catch(BaseException be){
			initErrorBean(be);
			be.printStackTrace();
		}
		return NAV_EDIT;
	}
	
	public String deleteAction(){
		try{
			service.deleteReInstateFreeTrx(resList, getThisUser());
		}catch(BaseException be){
			initErrorBean(be);
			be.printStackTrace();
		}
		return NAV_LIST;
	}
}
